# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=shapelib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=2
pkgdesc="simple C API for reading and writing ESRI Shapefiles (mingw-w64)"
arch=('any')
url="http://shapelib.maptools.org/"
license=("LGPL" "MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-proj")
options=(strip staticlibs)
source=("http://download.osgeo.org/shapelib/${_realname}-${pkgver}.tar.gz"
        shapelib_autotools.patch
        shapelib_backports.patch)
sha256sums=('23d474016158ab5077db2f599527631706ba5c0dc7c4178a6a1d685bb014f68f'
            '7c55f54a3cd4e45a29293c66228b2d9fa962491d5bdd10d2ec3b36fa78753ed1'
            'e34e9f19df344662aa695c40e29dd7c717c7f94d367b2564b0b988fad731f0c0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/shapelib_autotools.patch
  patch -p1 -i ${srcdir}/shapelib_backports.patch

  NOCONFIGURE=1 sh ./autogen.sh
}

build() {
  #export lt_cv_deplibs_check_method='pass_all'
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
